<?php

namespace App\Models;

use App\Models\Base;

/**
 * App\Models\Auth
 *
 * @property-write mixed $route_name
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Auth newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Auth newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Auth query()
 * @mixin \Eloquent
 */
class Auth extends Base
{
    public function setRouteNameAttribute($value)
    {
        $this->attributes['route_name'] = empty($value) ? '' : $value;
    }

    public function getAllList($type = 1, $idArray = true)
    {
        //全部权限
        if ($type == 1) {
            $data = self::get()->toArray();
        } else {
            //全部菜单
            if (is_array($idArray)) {
                $data = self::where('is_menu', '1')->whereIn('id', $idArray)->get()->toArray();
            } else {
                $data = self::where('is_menu', '1')->get()->toArray();
            }
        }
        return $this->get_tree_list($data);
    }
}
